﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SQLiteDictionary
{
    public class SQLiteEnum<TKey, TValue>
        where TKey : IEquatable<TKey>
    {
        public string DataBaseLocal
        { get; private set; }
        public TKey Key
        { get; private set; }
        public TValue Value
        {
            get { return Dictionary.Get(Key); }
            set { Dictionary[Key] = value; }
        }
        public SqliteDictionary<TKey, TValue> Dictionary
        {
            get
            {
                if (DataBaseLocal == null)
                    return new SqliteDictionary<TKey, TValue>();
                return new SqliteDictionary<TKey, TValue>(DataBaseLocal);
            }
        }

        public SQLiteEnum(TKey key, TValue DefaultValue)
        {
            Key = key;
            DataBaseLocal = null;
            Dictionary.Create(key, DefaultValue);
        }
        public SQLiteEnum(TKey key, TValue DefaultValue, string DataBasePath)
        {
            Key = key;
            DataBaseLocal = DataBasePath;
            Dictionary.Create(key, DefaultValue);
        }
        public SQLiteEnum(TKey key, TValue DefaultValue, SQLiteDictionaryStorage StorageFolder, string DataBaseName)
        {
            Key = key;
            DataBaseLocal = StorageLocal.GetPath(StorageFolder, DataBaseName);
            Dictionary.Create(key, DefaultValue);
        }
        

        public static implicit operator TValue(SQLiteEnum<TKey, TValue> Var)
        {
            return Var.Value;
        }
    }
}
